import LevelBaseControl from "../LevelCommon/LevelBaseControl";
import MoveObj from "../Prefabs/InteractivObj/Common/MoveObj";
import RotateObj from "../Prefabs/InteractivObj/Common/RotateObj";
import Gate from "../Prefabs/InteractivObj/Gate";
import { utils } from "../../utils/CommonUtil";
import GamePropConst from "../../constant/GamePropConst";
import EnumData from "../../Enum/EnumData";
import DialogDataConst from "../../constant/DialogDataConst";

export default class LevelControl6 extends LevelBaseControl{
    
    //#region room1
    /** 水龙头阀门*/
    private longtou_famen:Laya.Sprite3D;
    /** 洗漱台的水*/
    private xishutaiWater:MoveObj;
    /** 洗漱台放过水没*/
    private isReleaseWater:boolean = false;
    /** 密码拼图2*/
    private passPicture2:Laya.Sprite3D;
    /** 密码拼图7*/
    private passPicture7:Laya.Sprite3D;
    /** 暗门*/
    private darkGate:RotateObj;
    /** 暗门是否打开了*/
    private isDarkGateOpen:boolean = false;
    /** 最后的大门*/
    private endGate:Gate;
    /** 投影雕塑*/
    private touYingObj:Laya.Sprite3D;    
   // #endregion
    //#region room2
    /** 密码机器的柜子门*/
    private passMachineGate:RotateObj;
    /** 保险箱的门*/
    private safeBoxGate:RotateObj;
    //#endregion

    protected startByBase(){
        this.InitRoom1();
        this.InitRoom2();
        this.passPicture2.active = false;
        this.passPicture7.active = false;
    }
   
    private InitRoom1()
    {
        let room1 = this.allLevelObjs[0].owner;
        let walls = room1.getChildByName("walls");
        let wall1 = walls.getChildByName("wall1");

        this.longtou_famen = wall1.getChildByName("Object026").getChildByName("longtou_famen") as Laya.Sprite3D;
        
        let xishutaiWaterObj = wall1.getChildByName("Object026").getChildByName("Plane001") as Laya.Sprite3D;
        this.xishutaiWater = utils.CommonUtils.CustomAddComponent(xishutaiWaterObj,MoveObj) as MoveObj;

        let passPictureRoot = walls.getChildByName("wall4").getChildByName("SM_Prop_Generator_01").getChildByName("objs");

        this.passPicture2 = passPictureRoot.getChildByName("obj2") as Laya.Sprite3D;

        this.passPicture7 = passPictureRoot.getChildByName("obj7") as Laya.Sprite3D;

        let darkGateObj = walls.getChildByName("wall2").getChildByName("door");
        this.darkGate = utils.CommonUtils.CustomAddComponent(darkGateObj,RotateObj) as RotateObj;

        let endGateObj =  walls.getChildByName("wall4").getChildByName("room1EndGate");
        this.endGate = utils.CommonUtils.CustomAddComponent(endGateObj,Gate) as Gate;

        this.touYingObj = room1.getChildByName("Container").getChildByName("SM_Prop_Pillar_01").getChildByName("deadTouYing") as Laya.Sprite3D;
    }

    private InitRoom2()
    {
        let room2 = this.allLevelObjs[1].owner;

        let passMachineGateObj =  room2.getChildByName("walls").getChildByName("wall1").getChildByName("SM_Prop_Atm_01").getChildByName("Box001");
        this.passMachineGate  = utils.CommonUtils.CustomAddComponent(passMachineGateObj,RotateObj) as RotateObj;

        let safeBoxGateObj = room2.getChildByName("walls").getChildByName("wall3").getChildByName("ChamferBox001").getChildByName("safeBox");
        this.safeBoxGate = utils.CommonUtils.CustomAddComponent(safeBoxGateObj,RotateObj) as RotateObj;
    }

    public  DoInteractObjLogic( _name:string):boolean
    {
        switch (_name)
        {
            /** 判断选择了龙头阀门道具 有就装上*/
            case "xishutai":
            case "waterCollider":
                if (this.IsSelectProp(GamePropConst.ID_Faucet_valve))
                {
                    this.UseCurProp();
                    this.longtou_famen.active = true;
                }
                break;
            /** 点击了龙头阀门 如果没放水 就放水*/
            case "longtou_famen":
                /** 如果还没放水*/
                if (!this.isReleaseWater)
                {
                    this.xishutaiWater.Interactive();
                    this.isReleaseWater = true;
                }
                break;
            /** 如果有拼图 就放上去*/
            case "obj2Pos":
                if (!this.passPicture2.active && this.IsSelectProp(GamePropConst.Electronic_component))
                {
                    this.UseCurProp();
                    this.passPicture2.active = true;
                }
                break;
            /** 如果有拼图 就放上去*/
            case "obj7Pos":
                if (!this.passPicture7.active && this.IsSelectProp(GamePropConst.Electronic_component))
                {
                    this.UseCurProp();
                    this.passPicture7.active = true;
                }
                break;
            /** 投影正确  开暗门*/
            case "dead touying_Unlock":
                this.darkGate.Interactive();
                this.isDarkGateOpen = true;
                break;
            /** 点击暗门 进入room2*/
            case "darkGateCollider":
                if (this.isDarkGateOpen)
                {                    
                    if (this.cameraControl.curRoateY == 0)
                    {
                        this.ChangeCurLevelObj(this.allLevelObjs[1], EnumData.CameraMoveEff.LeftToRight);
                    }
                    else
                    {
                        this.ChangeCurLevelObj(this.allLevelObjs[1], EnumData.CameraMoveEff.RightToLeft);
                    }
                }
                break;
            /** 电子元件拼图正确 开门*/
            case "SM_Prop_Generator_01_UnLock":
                this.ShowDialog(DialogDataConst.open_gate);
                this.endGate.SetOpen();
                break;
            /** 电子元件拼图正确 开门*/
            case "room1EndGate_In_Gate":
                this.FinishLevel();
                break;
            /** 如果选了投影雕塑 就使用 放上去*/
            case "touyingtai":
                if (this.IsSelectProp(GamePropConst.Strange_sculpture))
                {
                    this.UseCurProp();
                    this.touYingObj.active = true;
                }
                break;
            /** room2**********************************************************************/
            /** 密码机器 密码对了*/
            case "SM_Prop_Atm_01_UnLock":
                this.passMachineGate.Interactive();
                break;
            /** 保险箱 密码锁开了*/
            case "physPassLock_UnLock":
                this.safeBoxGate.Interactive();
                break;
            /** 房间2的暗门 通往room1*/
            case "darkGateRoom2":
                if (this.cameraControl.curRoateY == 180 || this.cameraControl.curRoateY == -180)
                {
                    this.ChangeCurLevelObj(this.allLevelObjs[0],EnumData.CameraMoveEff.LeftToRight);
                }
                else
                {
                    this.ChangeCurLevelObj(this.allLevelObjs[0],EnumData.CameraMoveEff.RightToLeft);
                }
                break;
            default:
                break;
        }
        return true;
    }
}